package com.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.MedicamentBean;
import com.project.dao.MedicamentDao;
import com.project.service.MedicamentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 药剂
 */
@Service
@Transactional
public class MedicamentServiceImpl extends ServiceImpl<MedicamentDao, MedicamentBean> implements MedicamentService {
    @Override
    public IPage<MedicamentBean> findAllMedicament(int pageNO, int pageSize) {
        Page<MedicamentBean> page = new Page<>(pageNO,pageSize);
        IPage<MedicamentBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addMedicament(MedicamentBean medicamentBean) {
this.save(medicamentBean);
    }

    @Override
    public IPage<MedicamentBean> findName(int pageNO, int pageSize, String medicamentName, String medicamentType, String medicamentCategory) {
        Page<MedicamentBean> page = new Page<>(pageNO,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (medicamentName!=null && !medicamentName.equals("")){
            wrapper.like("medicament_name",medicamentName);
        }
        if (medicamentType!=null && !medicamentType.equals("")){
            wrapper.like("medicament_type",medicamentType);
        }
        if (medicamentCategory!=null && !medicamentCategory.equals("")){
            wrapper.like("medicament_category",medicamentCategory);
        }
        IPage<MedicamentBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
